package br.uff.es2.xadrez.core;

public class Rook extends Piece {

    public Rook(Color color, String imageFilePath) {
        this.color = color;
        this.imageFilePath = imageFilePath;
        this.moved = false;
        this.value = 5;
    }

    @Override
    public int[][] getAvaiableMoves(int[] posicao, Piece[][] board) {
        boolean blockUp = false;
        boolean blockDown = false;
        boolean blockRight = false;
        boolean blockLeft = false;
        int[][] availableMoves = new int[8][8];
        for (int x = 1; x < 8; x++) {
            if (posicao[0]+x < 8 && !blockDown) {
                if (board[posicao[0]+x][posicao[1]] == null) {
                    availableMoves[posicao[0]+x][posicao[1]] = 1;
                } else {
                    blockDown = true;
                    if (board[posicao[0]+x][posicao[1]].getColor() != getColor()) {
                        availableMoves[posicao[0]+x][posicao[1]] = 1;
                    }
                }
            }
            if (posicao[0]-x >= 0 && !blockUp) {
                if (board[posicao[0]-x][posicao[1]] == null) {
                    availableMoves[posicao[0]-x][posicao[1]] = 1;
                } else {
                    blockUp = true;
                    if (board[posicao[0]-x][posicao[1]].getColor() != getColor()) {
                        availableMoves[posicao[0]-x][posicao[1]] = 1;
                    }
                }
            }
            if (posicao[1]+x < 8 && !blockRight) {
                if (board[posicao[0]][posicao[1]+x] == null) {
                    availableMoves[posicao[0]][posicao[1]+x] = 1;
                } else {
                    blockRight = true;
                    if (board[posicao[0]][posicao[1]+x].getColor() != getColor()) {
                        availableMoves[posicao[0]][posicao[1]+x] = 1;
                    }
                }
            }
            if (posicao[1]-x >= 0 && !blockLeft) {
                if (board[posicao[0]][posicao[1]-x] == null) {
                    availableMoves[posicao[0]][posicao[1]-x] = 1;
                } else {
                    blockLeft = true;
                    if (board[posicao[0]][posicao[1]-x].getColor() != getColor()) {
                        availableMoves[posicao[0]][posicao[1]-x] = 1;
                    }
                }
            }
        }
        return availableMoves;
    }
}